package com.cloud.core.multistate;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.cloud.core.R;
import com.dylanc.loadinghelper.LoadingHelper;

/**
 * Created by Chen on 2020/10/22.
 * Description：
 */
public class EmptyAdapter extends LoadingHelper.Adapter<EmptyAdapter.ViewHolder> {

    @NonNull
    @Override
    public EmptyAdapter.ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new EmptyAdapter.ViewHolder(inflater.inflate(R.layout.layout_empty, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull final EmptyAdapter.ViewHolder holder) {
        holder.viewReload.setOnClickListener(v -> {
            if (holder.getOnReloadListener() != null) {
                holder.getOnReloadListener().onReload();
            }
        });
    }

    public static class ViewHolder extends LoadingHelper.ViewHolder {

        private final View viewReload;

        ViewHolder(@NonNull View rootView) {
            super(rootView);
            viewReload = rootView.findViewById(R.id.view_reload);
        }
    }
}
